'use strict';
const db = uniCloud.database()

exports.main = async (event, context) => {
    const collection = db.collection('todo')

    // 获取昨天的日期
    const yesterday = new Date()
    yesterday.setDate(yesterday.getDate() - 1)
    yesterday.setHours(0, 0, 0, 0)

    // 删除昨天之前的待办事项
    try {
        await collection.where({
            createTime: {
                $lt: yesterday
            }
        }).remove()

        return {
            code: 0,
            message: '清理成功'
        }
    } catch (error) {
        return {
            code: -1,
            message: '清理失败'
        }
    }
} 